#coding=utf-8

import pika

# 设置MQ环境
env = "localhost"

if env == "localhost": # 本机测试
    mq_info = {
        "username": "guanfuchang",
        "password": "12345678",
        "host": "localhost",
        "virtual_host": "/vhost_qa"
    }
elif env == "pt_test": # 测试环境测试
    mq_info = {
        "username": "",
        "password": "",
        "host": "",
        "virtual_host": ""
    }


def get_connection():
    """
    获取MQ连接
    :return:
    """
    # 连接MQ
    user_pwd = pika.PlainCredentials(username=mq_info.get("username"), password=mq_info.get("password"))
    connection = pika.BlockingConnection(pika.ConnectionParameters(host=mq_info.get("host"),
                                                                   virtual_host=mq_info.get("virtual_host"),
                                                                   credentials=user_pwd))
    return connection


if __name__ == '__main__':
    print(get_connection())

